#include "StdAfx.h"
#include "SourceManager.h"

namespace AST{

SourceManager::SourceManager(void)
{
}

bool SourceManager::addSource( char* filename){
	
	std::ifstream sourceTU;
	char  sourceline[10];
	std::stringstream sourceStream;

	sourceTU.open(filename,std::ifstream::binary);
	while ( sourceTU.good() )
    {
		sourceTU.get (sourceline,10,(char) 0);
		sourceStream << std::string(sourceline); 
	}
	std::string* sourceString = new std::string(sourceStream.str());
	sourceTU.close();

	sourceMap[std::string(filename)] = sourceString;

	return true;
}

std::string* SourceManager::getSource(std::string file){
	SourceDict::iterator iter;
	iter = sourceMap.find(file);
	if (iter != sourceMap.end())
		return iter->second;
	else
		return NULL;
}

SourceManager::~SourceManager(void)
{
	for(SourceDict::iterator iter= sourceMap.begin(); iter != sourceMap.end();iter++){
		delete iter->second;
	}
}

}//namespace AST
